package com.javacrafting.mifos.acceptance.dsl;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;


public class MifosSpikeDsl {

	public static void visit(Page pageObject, WebDriver driver) {
		driver.get("http://localhost:8080/mifosspike/" + pageObject.url());
	}
	
	public static void loginAs(MifoUser mifosUser, WebDriver driver) {
		WebElement usernameTextfield = driver.findElement(By.name("j_username"));
		usernameTextfield.sendKeys(mifosUser.username());
		WebElement passwordTextfield = driver.findElement(By.name("j_password"));
		passwordTextfield.sendKeys(mifosUser.password());
		
		passwordTextfield.submit();
	}

	public static void logout(WebDriver driver) {
		visit(new LogoutPage(), driver);
	}
	
	// syntactic sugar methods
	public static WebDriver using(WebDriver driver) {
		return driver;
	}
}
